<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>跟随鼠标的天使</title>
		
		<style type="text/css">
			
			img {
				position: absolute;
			}
		</style>
	</head>
	<body>
		<img src="img/angel.gif"/>
		
		<script type="text/javascript">
			//获取图片对象
			var img = document.querySelector('img');
			//监听鼠标移动事件
			document.addEventListener('mousemove',function(e) {
				//获取鼠标相对于网页文档的坐标
				var x = e.pageX;
				var y = e.pageY;
				
				//设置图片绝对定位的位置
				img.style.top = y - 50 + 'px';
				img.style.left = x + 20 + 'px';
			})
		</script>
	</body>
</html>
